package cn.com.cym.gamezao.entity.authorize;


import cn.com.cym.gamezao.base.BaseEntity;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.Accessors;
import org.springframework.lang.NonNull;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Set;

/**
 * 角色
 */
@ApiModel(description="用户角色")
@Table(name="a_role",uniqueConstraints=@UniqueConstraint(columnNames="code"))
@Entity
@Getter
@Setter
@Accessors(chain = true)
@NoArgsConstructor
public class Role extends BaseEntity implements Serializable {
    private static final long serialVersionUID = 3408156591856885587L;

    @ApiModelProperty(value = "角色名称",dataType = "String")
    @Column(length = 48,unique = true)
    private String name;

    @ApiModelProperty(value = "角色代码",dataType = "String")
    @Column(length = 12,unique = true)
    @NonNull
    private String code;

    @ApiModelProperty(value = "角色描述",dataType = "String")
    @Column(length = 120)
    private String roleDesc;

    //@Transient
    @ApiModelProperty(value = "用户角色",dataType = "RoleUser")
    @OneToMany(mappedBy="role",fetch = FetchType.EAGER)
    @JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
    private Set<UserRole> roleUsers;

    @ApiModelProperty(value = "角色对应权限",dataType = "RoleAuthorize")
    @OneToMany(mappedBy="role",fetch = FetchType.EAGER)
    private  Set<RoleAuthorize>  roleAuthorizes;


}
